{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9aa07450",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9a1b607b",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"data/ssd_failure_tag.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "949c427b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Delete the data with model C1 or C2\n",
    "df = df.drop(df.index[(df['model'] == 'C1') | (df['model'] == 'C2')])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1c2603ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "dict_ = {'A3': '20nm',\n",
    "                'A6': '20nm',\n",
    "                'A4': '16nm',\n",
    "                'A1': '20nm',\n",
    "                'A5': '16nm',\n",
    "                'A2': '20nm',\n",
    "                'B2': '19nm',\n",
    "                'B3': '24nm',\n",
    "                'B1': '21nm'\n",
    "        }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e3ffc376",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['lithography'] = df['model']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d2018c1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "for key, value in dict_.items():\n",
    "            df['lithography'] = df['lithography'].replace(key, value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "64c4b7b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "grouped = df.groupby('lithography')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7630db1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "res_df = pd.DataFrame(columns=['lithography','failure','all','percentage'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1e713058",
   "metadata": {},
   "outputs": [],
   "source": [
    "row = 0\n",
    "for col, group in grouped:\n",
    "    res_df.loc[row] = [col,group.shape[0], '','']\n",
    "    row = row + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "66c96105",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_all = pd.read_csv(\"data/20191231.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2ad3756f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Delete the data with model C1 or C2\n",
    "df_all = df_all.drop(df_all.index[(df_all['model'] == 'C1') | (df_all['model'] == 'C2')])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1867907c",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_all['lithography'] = df_all['model']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6e58e448",
   "metadata": {},
   "outputs": [],
   "source": [
    "grouped = df_all.groupby('lithography')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f92c0707",
   "metadata": {},
   "outputs": [],
   "source": [
    "for key, value in dict_.items():\n",
    "            df_all['lithography'] = df_all['lithography'].replace(key, value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e8b50ff8",
   "metadata": {},
   "outputs": [],
   "source": [
    "row = 0\n",
    "for col, group in grouped:\n",
    "    res_df.iloc[row, 2] = group.shape[0]\n",
    "    res_df.iloc[row, 3] = res_df.iloc[row, 1] * 100 / res_df.iloc[row, 2]\n",
    "    row = row + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "6fd6a434",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  lithography failure     all percentage\n",
      "0        16nm     721   63585   1.133915\n",
      "1        19nm     604   43443   1.390328\n",
      "2        20nm    3226  283868   1.136444\n",
      "3        21nm     388   89067   0.435627\n",
      "4        24nm    1807   38564   4.685717\n"
     ]
    }
   ],
   "source": [
    "print(res_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0dabc937",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='Lithography', ylabel='RFR'>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAEGCAYAAABvtY4XAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAPRUlEQVR4nO3de4yldX3H8feHi4pVrHZHQwUcbBEL5aIdaS2mrUQNihHaWgtRCq1006beUi9B26byT0Ns473VbJCuWIIxitRKqqUKUpVLZ2HltlwMXZSK7lpUoFUU9ts/nmeYs8vMDu7uc87Mb96vZDLPbc7ve3575nN+8+zz/E6qCklSe/aadAGSpGEY8JLUKANekhplwEtSowx4SWrUPpMuYNSaNWtqenp60mVI0oqxYcOG71bV1EL7llXAT09PMzs7O+kyJGnFSHLnYvs8RSNJjTLgJalRBrwkNcqAl6RGGfCS1CgDXpIaZcBLUqMMeElqlAEvSY1aVneyStK4TJ91yaRLAGDzOScO9tiO4CWpUQa8JDXKgJekRhnwktQoA16SGmXAS1KjDHhJapQBL0mNMuAlqVEGvCQ1yoCXpEYZ8JLUKANekhplwEtSowx4SWqUAS9JjTLgJalRBrwkNcqAl6RGGfCS1CgDXpIaZcBLUqMMeElqlAEvSY0y4CWpUQa8JDVq8IBPsneS65J8dui2JEnzxjGCfyOwaQztSJJGDBrwSQ4ETgTOHbIdSdIjDT2Cfy/wNmDbYgckWZtkNsns1q1bBy5HklaPwQI+ycuBLVW1YWfHVdW6qpqpqpmpqamhypGkVWfIEfxxwCuSbAY+Dhyf5J8GbE+SNGKwgK+qt1fVgVU1DZwCfLGqXjNUe5Kk7XkdvCQ1ap9xNFJVlwOXj6MtSVLHEbwkNcqAl6RGGfCS1CgDXpIaZcBLUqMMeElqlA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2UQ3pbW025xNUtpBkscCD1XVg0meD3yoqo75KR9jM93H3T3qzxpI8ni6T0N67tynJkm7wxG89EgH032U4150H0X3x0M3mORFdFfSvMdw157iCF6SGuV/skpSowx4SWqUAS9JjTLgJalRBrwkNer/AXyihT7p6y93AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "res_df.plot(x = 'lithography', y = 'percentage', kind='bar', rot = 0, xlabel = 'Lithography', ylabel = 'RFR', legend = None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c185d77",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
